<?php

/**
 * This is the model class for table "{{customer_address_log}}".
 *
 * The followings are the available columns in table '{{customer_address_log}}':
 * @property integer $id
 * @property integer $customerId
 * @property string $postalAddress
 * @property string $postalSuburb
 * @property string $postalPostcode
 * @property string $postalState
 * @property string $postalCountry
 * @property string $changeDate
 * @property integer $changeUserId
 *
 * The followings are the available model relations:
 * @property User $changeUser
 * @property Customer $customer
 */
class CustomerAddressLog extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return CustomerAddressLog the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{customer_address_log}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('customerId, changeUserId', 'numerical', 'integerOnly'=>true),
			array('postalAddress, postalSuburb, postalPostcode, postalState, postalCountry', 'length', 'max'=>255),
			array('changeDate', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, customerId, postalAddress, postalSuburb, postalPostcode, postalState, postalCountry, changeDate, changeUserId', 'safe', 'on'=>'search'),
		);
	}

	public function behaviors(){
		return array(
	  		'CTimestampBehavior' => array(
	  			'class' => 'zii.behaviors.CTimestampBehavior',
	  			'createAttribute' => 'changeDate',
				'updateAttribute' => null,
			),
			'SetCurrentUserBehavior'=>array(
				'class'=>'application.behavior.SetCurrentUserBehavior',
				'createUserIdAttribute'=>'changeUserId',
			),
			'DateFieldBehavior'=>array(
				'class'=>'application.behavior.DateFieldBehavior',
				'dateField'=>'changeDate',
			),
		);
	}
	
	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'changeUser' => array(self::BELONGS_TO, 'User', 'changeUserId'),
			'customer' => array(self::BELONGS_TO, 'Customer', 'customerId'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'customerId' => 'Customer',
			'postalAddress' => 'Postal Address',
			'postalSuburb' => 'Postal Suburb',
			'postalPostcode' => 'Postal Postcode',
			'postalState' => 'Postal State',
			'postalCountry' => 'Postal Country',
			'changeDate' => 'Change Date',
			'changeUserId' => 'Change User',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('customerId',$this->customerId);
		$criteria->compare('postalAddress',$this->postalAddress,true);
		$criteria->compare('postalSuburb',$this->postalSuburb,true);
		$criteria->compare('postalPostcode',$this->postalPostcode,true);
		$criteria->compare('postalState',$this->postalState,true);
		$criteria->compare('postalCountry',$this->postalCountry,true);
		$criteria->compare('changeDate',$this->changeDate,true);
		$criteria->compare('changeUserId',$this->changeUserId);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}